#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
bool vis[201][201] = { false };
int solve(vector<vector<char>>& grid)
{
    int size = 0;
    int m = grid.size(), n = grid[0].size();
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int count = 0;
            if (!vis[i][j] && grid[i][j] == '1')
            {
                for (int k = 0; k < 4; k++)
                {
                    int a = i + dx[k];
                    int b = j + dy[k];
                    if (a >= 0 && a < m && b >= 0 && b < n && grid[a][b] == '1' && !vis[a][b])
                    {
                        count++;
                        vis[a][b] = true;
                    }
                }
                if (count)
                {
                    size++;
                    vis[i][j] = true;
                }
            }
        }
    }
    return size;
}
int main()
{
    vector<vector<char>> grid = { {'1','1','0','0','0'},{'0','1','0','1','1'},\
    {'0','0','0','1','1'},{'0','0','0','0','0'},{'0','0','1','1','1'} };
    solve(grid);
	return 0;
}